// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import timeC from "../UIS/timeC";
import state from "../game/time/state";
import turn from "../game/time/turn";
import player from "../game/player";

import GeZiManager from "../Manager/GeZiManager";

import MessageCenter from "./MessageCenter";
import KHD from "./KHD";
import AnimalManager from "../Manager/AnimalManager";
import MUI from "../UIS/MMUI/MUI";
import { Message } from "./Message";
import ZManager from "../Manager/ZManager";
import KHD2 from "./KHD2";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Pchange extends cc.Component {
static timeC:timeC=null;
t:number=0
  
tt(){
switch (this.t) {
  case 1:this.t=0;cc.find("Canvas/UIManager/tiaoshi").y+=300
    
    break;

  default:this.t=1;cc.find("Canvas/UIManager/tiaoshi").y-=300
    break;
}

  
}



p1(){
KHD2.PT=[3,1,3,5]
player.Pturn=[1]

state.Pchange();
//Pchange.timeC.resetTimer ()


}
 p2(){
  KHD2.PT=[4,2,4,6]
    player.Pturn=[2]
   
   
    state.Pchange();
   //Pchange.timeC. resetTimer ()



}

 p3(){
  KHD2.PT=[3]
        player.Pturn=[3]
        state.Pchange();
      //Pchange.timeC. resetTimer ()

   

    }

p4(){
  KHD2.PT=[4]
            player.Pturn=[4]
            state.Pchange() 
            //Pchange.timeC. resetTimer ()

       

          }
p5(){
  KHD2.PT=[5]
player.Pturn=[5]
state.Pchange() 
//Pchange.timeC. resetTimer ()



}

 p6(){ KHD2.PT=[6]
                    player.Pturn=[6]
                    state.Pchange() ;
                  // Pchange.timeC. resetTimer ()
            

             }




              start() {
                   
              let a=  cc.find("Canvas/TimeC")
              Pchange.timeC=a.getComponent(timeC);

              
            }
     TN() { MessageCenter.MakeSHMessage("AM",[GeZiManager.PCP.ZB],5,GeZiManager.PCP.Pturn,"TN=");
     MessageCenter.MakeMessage("UIManager","change",1)
    
   





     }      
          
qiadd(){ MessageCenter.MakeMessage("AM",turn.turn,"getC"); MessageCenter.MakeSHMessage("AM",[GeZiManager.PCP.ZB],1,null,"Qi+") } 
qidd(){ MessageCenter.MakeMessage("AM",turn.turn,"getC"); MessageCenter.MakeSHMessage("AM",[GeZiManager.PCP.ZB],1,null,"Qi-") }         
          
  round(){ 
    MessageCenter.MakeGMessage("GM",[0], turn.turn+1, turn.turn,"PASS"); 
    MessageCenter.MakeGMessage("GM",[0], turn.turn+1, turn.turn,"PASS"); 
    MessageCenter.MakeGMessage("GM",[0], turn.turn+1, turn.turn,"PASS"); 
    MessageCenter.MakeGMessage("GM",[0], turn.turn+1, turn.turn,"PASS"); 
    MessageCenter.MakeGMessage("GM",[0], turn.turn+1, turn.turn,"PASS"); 
    MessageCenter.MakeGMessage("GM",[0], turn.turn+1, turn.turn,"PASS"); }      
      
   MCD(){ cc.find("Canvas/UIManager/magicUI").getComponent(MUI).MCD=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
   
    cc.find("Canvas/UIManager/magicUI").getComponent(MUI).ST();
    MessageCenter.MakeMessage("UIManager","change",-1)
    for(let mannger of GeZiManager.YuanGong){

      let a=""
     let message=new Message(a,[65],-1)
      mannger.ReceiveMessage(message)
  }
     for(let mannger of GeZiManager.YuanGong){
        
        
      let a=""
     let message=new Message(a,GeZiManager.BanMove,5)
      mannger.ReceiveMessage(message)
      
   
  }
  
  }
  MCD1(){ cc.find("Canvas/UIManager/magicUI").getComponent(MUI).MCD=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
   
    cc.find("Canvas/UIManager/magicUI").getComponent(MUI).ST();
    MessageCenter.MakeMessage("UIManager","change",-1)
    for(let mannger of GeZiManager.YuanGong){

      let a=""
     let message=new Message(a,[65],-1)
      mannger.ReceiveMessage(message)
  }
     for(let mannger of GeZiManager.YuanGong){
        
        
      let a=""
     let message=new Message(a,GeZiManager.boxs,5)
      mannger.ReceiveMessage(message)
      
   
  }
  
  }
text(){
  MessageCenter.Text=true


  state.state=1;
  MessageCenter.MakeGMessage("AM",[AnimalManager.FF[0]],1,1,"FTP");
     
       

  MessageCenter.MakeGMessage("AM",[AnimalManager.FF[1]],1,1,"FTP");
  
  MessageCenter.MakeGMessage("AM",[AnimalManager.FF[2]],2,2,"FTP");
  cc.find("Canvas/DituManager/New Node/AnimalManager").getComponent(ZManager).Cx()

  AnimalManager.TP(1,43);
  console.log(GeZiManager.P1.ZB)
  AnimalManager.TP(2,38)
 AnimalManager.TP(3,34)
 AnimalManager.TP(4,39)
 AnimalManager.TP(5,18)
  AnimalManager.TP(6,30)
 turn.turn=1
  console.log(turn.turn)
  console.log(  GeZiManager.PCP)
  MessageCenter.MakeMessage("AM",turn.turn,"getC"); 
  state.Pchange() ;  
  
  GeZiManager.PCP.Tstart();

  state.ST=1;
  MessageCenter.MakeSHMessage("TN",this.makePool(),0,0,"pool")
}



texr(){
  KHD2.PT=[3,1,3,5]
  MessageCenter.Text=true


 // state.state=1;
  MessageCenter.MakeGMessage("AM",[AnimalManager.FF[0]],1,1,"FTP");
     
       

  MessageCenter.MakeGMessage("AM",[AnimalManager.FF[1]],1,1,"FTP");
  
  MessageCenter.MakeGMessage("AM",[AnimalManager.FF[2]],2,2,"FTP");
  cc.find("Canvas/DituManager/New Node/AnimalManager").getComponent(ZManager).Cx()

 
 turn.turn=1
  console.log(turn.turn)
  console.log(  GeZiManager.PCP)
  MessageCenter.MakeMessage("AM",turn.turn,"getC"); 
  state.Pchange() ;  
  
  GeZiManager.PCP.Tstart();

 // state.ST=1;
  MessageCenter.MakeSHMessage("TN",this.makePool(),0,0,"pool")
}


makePool(): number[][] {
  const pools: number[][] = [];
  for (let j = 0; j < 3; j++) {
    const validNumbers = [0, 1, 2, 3, 5, 7]; // 可选数字集合，只包含0和1
    const arr = [1]; // 第二个数字是2
    let lastNumber = 2; // 上一个数字是2
    let twoCount = 1; // 统计出现的2的个数
    let oneCount = 0; // 统计出现的1的个数
    for (let i = 1; i < 12; i++) {
      const candidates = validNumbers.filter(n => n !== lastNumber); // 候选数字集合不能与上一个数字相同
      if (twoCount < 2&&i>3) {
        candidates.push(2); // 如果已经有不足3个2，则候选数字集合中添加2
      }
      if (oneCount < 2&&i>4) {
        candidates.push(3); // 如果已经有不足4个1，则候选数字集合中添加1
      }
      const numberIndex = Math.floor(Math.random() * candidates.length); // 随机选取一个数字
      const number = candidates[numberIndex];
      arr.push(number);
      lastNumber = number;
      if (number === 1) {
        oneCount++;
      } else {
        oneCount = 0;
      }
      if (number === 2) {
        twoCount++;
      } else {
        twoCount = 0;
      }
    }
    arr[3]=6;
    arr[6]=6;
    arr[10]=6;
    pools.push(arr);
  }
  const mergedArray = [].concat(...pools);
  console.log(mergedArray); // 打印合并后的一维数组
  return mergedArray;
}
      
          }

                
